home *** CD-ROM | disk | FTP | other *** search
/ 100 Plus Great Games 2 / 100PLUSV2.BIN / games / CrazyCreeps.dxr / 00006_Player Script.ls < prev    next >
Encoding:
Text File  |  2002-01-25  |  10.1 KB  |  355 lines

  1. property pMySpriteNum, pState, pLocation, pVelocity, pCurrAnim, pAnimations, pCurrFrame, pLastAnimationUpdate, pInvincibleTimer, pbInvincible, MAX_SPEED, INVINCIBLE_TIME, pLast
  2. global gLives, gBallDead, gEnemyCount2, gLevel, gWon, gScore, gBallSpriteNum
  3.  
  4. on new me, mySpriteNum, myLocation
  5.   pLast = 0
  6.   pMySpriteNum = mySpriteNum
  7.   gBallSpriteNum = pMySpriteNum
  8.   pState = #flying
  9.   pLocation = myLocation
  10.   pVelocity = [0.0, 0.0, 0.0]
  11.   sprite(pMySpriteNum).puppet = 1
  12.   sprite(pMySpriteNum).member = member(46)
  13.   sprite(pMySpriteNum).ink = 8
  14.   sprite(pMySpriteNum).loc = point(pLocation[1], pLocation[2])
  15.   pCurrAnim = #flying
  16.   pAnimations = [#Run: [46, 47, 48, 49, 50, 51, 52, 53, 54, 55], #takeOff: [46, 47, 48, 49, 50, 51, 52, 53, 54, 55], #flying: [46, 47, 48, 49, 50, 51, 52, 53, 54, 55], #dead: [46, 47, 48, 49, 50, 51, 52, 53, 54, 55]]
  17.   pCurrFrame = 1
  18.   pLastAnimationUpdate = the ticks
  19.   MAX_SPEED = 4.0
  20.   INVINCIBLE_TIME = 120
  21.   pInvincibleTimer = the ticks + 120
  22.   pbInvincible = 1
  23.   return me
  24. end
  25.  
  26. on update me
  27.   if gBallDead = 1 then
  28.     sprite(10).blend = sprite(10).blend - 10
  29.     if sprite(10).blend < 20 then
  30.       sprite(10).blend = 0
  31.       sprite(10).visible = 0
  32.     end if
  33.   end if
  34.   if gBallDead = 1 then
  35.     if (gLevel = 1) or (gLevel = 2) then
  36.       if sprite(10).locV > 360 then
  37.         setState(#dead)
  38.       end if
  39.     end if
  40.     if (gLevel = 3) or (gLevel = 4) or (gLevel = 5) then
  41.       if sprite(10).locV > 380 then
  42.         setState(#dead)
  43.       end if
  44.     end if
  45.   end if
  46.   if pState <> #dead then
  47.     if pState <> #takeOff then
  48.       collisionCheck()
  49.     end if
  50.     enemyCollisionCheck()
  51.     handleInput()
  52.     theAngle = getAngle(pLocation, the mouseLoc)
  53.     if the stillDown and (gBallDead = 0) then
  54.       if pState = #onGround then
  55.         pVelocity[2] = -2.0
  56.         setState(#flying)
  57.       else
  58.         if pState = #flying then
  59.           radAngle = theAngle * PI / 180
  60.           oX = cos(radAngle) * 1.0
  61.           oY = -sin(radAngle) * 1.0
  62.           pVelocity = pVelocity + [oX, oY]
  63.         end if
  64.       end if
  65.     else
  66.       if pState = #flying then
  67.       end if
  68.     end if
  69.   end if
  70.   case pState of
  71.     #onGround:
  72.       if (pVelocity[1] > -1.0) and (pVelocity[1] < 1.0) then
  73.         pVelocity[1] = 0.0
  74.       end if
  75.       if pVelocity[1] <> 0.0 then
  76.       else
  77.         sprite(pMySpriteNum).member = member(46)
  78.       end if
  79.       if pVelocity[2] > 0.0 then
  80.         pVelocity[2] = 0.0
  81.       end if
  82.       pLocation = pLocation + pVelocity
  83.     #flying:
  84.       pVelocity[2] = pVelocity[2] + 0.20000000000000001
  85.       pLocation = pLocation + pVelocity
  86.     #dead:
  87.       if pCurrAnim <> #dead then
  88.       else
  89.         if keyPressed(SPACE) then
  90.           respawn()
  91.         end if
  92.         if pLocation[2] < 400 then
  93.           pVelocity[1] = pVelocity[1] * 0.90000000000000002
  94.           pVelocity[2] = pVelocity[2] + 0.20000000000000001
  95.           pLocation = pLocation + pVelocity
  96.         else
  97.           if pCurrAnim <> #dead then
  98.             puppetSound(4, "cricketguyfall")
  99.             pCurrAnim = #dead
  100.             pCurrFrame = 1
  101.             pLocation[2] = 400
  102.           end if
  103.         end if
  104.       end if
  105.   end case
  106.   if pLocation[1] < -5.0 then
  107.     pLocation[1] = 580.0
  108.   end if
  109.   if pLocation[1] > 585.0 then
  110.     pLocation[1] = 0.0
  111.   end if
  112.   if pLocation[2] < 12.0 then
  113.     pLocation[2] = 12.0
  114.     pVelocity[2] = 0.0
  115.   end if
  116.   sprite(pMySpriteNum).loc = point(pLocation[1], pLocation[2])
  117.   if pVelocity[1] > MAX_SPEED then
  118.     pVelocity[1] = MAX_SPEED
  119.   end if
  120.   if pVelocity[2] > MAX_SPEED then
  121.     pVelocity[2] = MAX_SPEED
  122.   end if
  123.   if pVelocity[1] < -MAX_SPEED then
  124.     pVelocity[1] = -MAX_SPEED
  125.   end if
  126.   if pVelocity[2] < -MAX_SPEED then
  127.     pVelocity[2] = -MAX_SPEED
  128.   end if
  129. end
  130.  
  131. on handleInput
  132.   if pLocation[1] < (the mouseLoc)[1] then
  133.     if pVelocity[1] < MAX_SPEED then
  134.       pVelocity[1] = pVelocity[1] + 0.5
  135.     end if
  136.   else
  137.     if pLocation[1] > (the mouseLoc)[1] then
  138.       if pVelocity[1] > -MAX_SPEED then
  139.         pVelocity[1] = pVelocity[1] - 0.5
  140.       end if
  141.     end if
  142.   end if
  143.   if gBallDead = 1 then
  144.     sprite(150).visible = 1
  145.     sprite(pMySpriteNum).member = "ballDead"
  146.   end if
  147. end
  148.  
  149. on setState theState
  150.   case theState of
  151.     #onGround:
  152.       pState = #onGround
  153.       pCurrAnim = #Run
  154.       pCurrFrame = 1
  155.     #takeOff:
  156.       pState = #takeOff
  157.       pCurrAnim = #takeOff
  158.       pCurrFrame = 1
  159.     #flying:
  160.       pState = #flying
  161.       pCurrAnim = #flying
  162.       pCurrFrame = 1
  163.     #dead:
  164.       pState = #dead
  165.       pCurrAnim = #flying
  166.       pCurrFrame = 1
  167.   end case
  168. end
  169.  
  170. on collisionCheck
  171.   c = sendSprite(0, #levelCollisionCheck, pMySpriteNum)
  172.   if gBallDead = 1 then
  173.     case gLevel of
  174.       1:
  175.         if c <> 6 then
  176.           exit
  177.         end if
  178.       2:
  179.         if c <> 2 then
  180.           exit
  181.         end if
  182.       3:
  183.         if c <> 7 then
  184.           exit
  185.         end if
  186.     end case
  187.   end if
  188.   if c then
  189.     if sprite(10).intersects(7) and ((gLevel = 3) or (gLevel = 4) or (gLevel = 5)) and (gBallDead = 0) then
  190.       gBallDead = 1
  191.       gLives = gLives - 1
  192.       put string(gLives) into member "Lives Display"
  193.       if gLives = 0 then
  194.         waitAWhile()
  195.         case gLevel of
  196.           1:
  197.             go(6)
  198.           2:
  199.             go(16)
  200.           3:
  201.             go(26)
  202.           4:
  203.             go(36)
  204.           5:
  205.             go(46)
  206.         end case
  207.         puppetSound(4, "lose")
  208.         member("WinOrLose").text = " Try Again"
  209.         member("WinOrLose2").text = " Try Again"
  210.         member("TotalDisp").text = "Total Score: " & gScore
  211.         member("TotalDisp2").text = "Total Score: " & gScore
  212.         puppetSound(5, "balldead!!!")
  213.       end if
  214.       exit
  215.     end if
  216.     playerRect = sprite(pMySpriteNum).rect
  217.     groundRect = sprite(c).rect
  218.     collisionRect = playerRect.intersect(groundRect)
  219.     if (collisionRect[2] = groundRect[2]) and (pVelocity[2] > 0.0) then
  220.       if (pState <> #onGround) and (pState <> #dead) then
  221.         setState(#onGround)
  222.       end if
  223.       pLocation[2] = collisionRect[2] - (sprite(pMySpriteNum).height / 2) + 5
  224.     end if
  225.   else
  226.     if pState = #onGround then
  227.       setState(#flying)
  228.     end if
  229.     nothing()
  230.   end if
  231. end
  232.  
  233. on enemyCollisionCheck
  234.   if sprite(10).blend >= 100 then
  235.     if gBallDead = 0 then
  236.       c = sendSprite(0, #enemyCollisionCheck, pMySpriteNum)
  237.       if c <> 0 then
  238.         if sprite(c).blend = 100 then
  239.           playerRect = sprite(pMySpriteNum).rect
  240.           enemyRect = sprite(c).rect
  241.           collisionRect = playerRect.intersect(enemyRect)
  242.           diffX = collisionRect[3] - collisionRect[1]
  243.           diffY = collisionRect[4] - collisionRect[2]
  244.           if diffY > diffX then
  245.             sendSprite(c, #reverseDirection)
  246.             pVelocity[1] = -pVelocity[1]
  247.             if pVelocity < 0.0 then
  248.               pLocation[1] = collisionRect[1] - (sprite(pMySpriteNum).width / 2) - 1
  249.             else
  250.               pLocation[1] = collisionRect[3] + (sprite(pMySpriteNum).width / 2) + 1
  251.             end if
  252.           else
  253.             if collisionRect[2] = enemyRect[2] then
  254.               if gLevel = 4 then
  255.                 if member(sprite(c).member).name = "badguy4" then
  256.                   sprite(c).member = member("adguy42")
  257.                 else
  258.                   sendSprite(c, #die)
  259.                   sprite(c).blend = 90
  260.                   sprite(pMySpriteNum).locV = sprite(pMySpriteNum).locV - 20
  261.                   update()
  262.                   pLocation[2] = pLocation[2] - 20
  263.                 end if
  264.               else
  265.                 if gLevel = 5 then
  266.                   if member(sprite(c).member).name = "levelfive_badguy" then
  267.                     sprite(c).member = member("evelfive_badguy2")
  268.                   else
  269.                     sendSprite(c, #die)
  270.                     sprite(c).blend = 90
  271.                     sprite(pMySpriteNum).locV = sprite(pMySpriteNum).locV - 20
  272.                     update()
  273.                     pLocation[2] = pLocation[2] - 20
  274.                   end if
  275.                 else
  276.                   sendSprite(c, #die)
  277.                   sprite(c).blend = 90
  278.                   sprite(pMySpriteNum).locV = sprite(pMySpriteNum).locV - 20
  279.                   pLocation[2] = pLocation[2] - 20
  280.                   update()
  281.                 end if
  282.               end if
  283.               sprite(pMySpriteNum).locV = sprite(pMySpriteNum).locV - 20
  284.               pLocation[2] = pLocation[2] - 20
  285.               pVelocity[2] = 0 - (2 * pVelocity[2])
  286.               if gEnemyCount2 = 0 then
  287.                 member("TotalDisp").text = "Total Score: " & gScore
  288.                 member("TotalDisp2").text = "Total Score: " & gScore
  289.                 waitAWhile()
  290.                 case gLevel of
  291.                   1:
  292.                     go(2)
  293.                   2:
  294.                     go(12)
  295.                   3:
  296.                     go(22)
  297.                   4:
  298.                     go(32)
  299.                   5:
  300.                     member("WinOrLose").text = "You Win!!"
  301.                     member("WinOrLose2").text = "You Win!!"
  302.                     puppetSound(4, "win10")
  303.                     go(46)
  304.                 end case
  305.                 gLevel = gLevel + 1
  306.                 put string(gLevel) into member "LevelDisplay"
  307.                 exit
  308.               end if
  309.             else
  310.               gBallDead = 1
  311.               gLives = gLives - 1
  312.               put string(gLives) into member "Lives Display"
  313.               if gLives = 0 then
  314.                 waitAWhile()
  315.                 case gLevel of
  316.                   1:
  317.                     go(6)
  318.                   2:
  319.                     go(16)
  320.                   3:
  321.                     go(26)
  322.                   4:
  323.                     go(36)
  324.                   5:
  325.                     go(46)
  326.                 end case
  327.                 puppetSound(4, "lose")
  328.                 member("WinOrLose").text = " Try Again"
  329.                 member("WinOrLose2").text = " Try Again"
  330.                 member("TotalDisp").text = "Total Score: " & gScore
  331.                 member("TotalDisp2").text = "Total Score: " & gScore
  332.               end if
  333.               puppetSound(5, "balldead!!!")
  334.             end if
  335.           end if
  336.         end if
  337.       else
  338.         nothing()
  339.       end if
  340.     end if
  341.   end if
  342. end
  343.  
  344. on respawn
  345. end
  346.  
  347. on handlePowerup me, powerupType
  348.   case powerupType of
  349.     #freeMan:
  350.       addALife()
  351.     #bonusPoints:
  352.       addScore(1000)
  353.   end case
  354. end
  355.